//
//  BdTV.m
//  Koina
//
//  Created by welldone on 13-8-10.
//  Copyright (c) 2013年 net.koina. All rights reserved.
//

#import "BdTV.h"
#import "config.h"

@interface BdTV ()
@property (nonatomic,retain) UILabel  *titleLable;

-(void)setleftImg:(NSString*)imgName;

-(void)setRightImg:(NSString*)imgName;

@end

@implementation BdTV
@synthesize backBtn,titleLable,doneBtn;


+(instancetype)creatInstanceWithTitle:(NSString *)tit{

    BdTV *titleV = [[BdTV  alloc]initWithFrame:CGRectMake(0, 0, PMW, 44)];
    [titleV setMianTitle:tit];

    return titleV;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        

        backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [backBtn setFrame:CGRectMake(0,0, 60, frame.size.height)];
        [backBtn setShowsTouchWhenHighlighted:YES];
        [self setleftImg:@"return_icon"];
        [self addSubview:backBtn];
        
        
        doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [doneBtn setFrame:CGRectMake(PMW-60,0,60, frame.size.height)];
                [doneBtn setShowsTouchWhenHighlighted:YES];
        [doneBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [doneBtn setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
        [doneBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        [self setRightImg:@"meunbei_ixon"];

        [self addSubview:doneBtn];

        
        
        titleLable = [[UILabel alloc]init];
        [titleLable setFont:[UIFont fontWithName:@"TrebuchetMS-Bold" size:17]];
        [titleLable setTextColor:[UIColor whiteColor]];
        [titleLable setBackgroundColor:[UIColor clearColor]];
        [self addSubview:titleLable];
        
    }
    return self;
}



-(void)setleftImg:(NSString*)imgName{

    UIImage *img = [UIImage imageNamed:imgName];
    [backBtn setImage:img forState:UIControlStateNormal];
    [backBtn setImageEdgeInsets:UIEdgeInsetsMake(backBtn.frame.size.height/2-img.size.height,-(backBtn.frame.size.width/2-img.size.width/2), 0, 0)];
}


-(void) setMianTitle:(NSString*)title{
   
    CGSize titleSize = [title sizeWithFont:titleLable.font];
    [titleLable  setFrame:CGRectMake(self.frame.size.width/2-titleSize.width/2, self.frame.size.height/2-titleSize.height/2, titleSize.width, titleSize.height)];
    [titleLable setText:title];
}


-(void)setRightImg:(NSString*)imgName{
    
    UIImage *img = [UIImage imageNamed:imgName];
    [doneBtn setImage:img forState:UIControlStateNormal];
    UIEdgeInsets red = UIEdgeInsetsMake(10,30,10,10);
    
    [doneBtn setImageEdgeInsets:red];
}

@end
